﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using ContractManagermentSystem.Business;
using ContractManagermentSystem.Entity;

namespace ContractManagermentSystem.Pages
{
    public partial class UpdateRole : System.Web.UI.Page
    {
        private RoleBus _roleBus;

        protected void Page_Load(object sender, EventArgs e)
        {
            var roleId = new Guid(Request.QueryString["Id"]);
            _roleBus = new RoleBus();
            if (!IsPostBack)
            {
                LoadRoleById();
            }
        }

        private void LoadRoleById()
        {
            var roleId = new Guid(Request.QueryString["Id"]);
            DataTable dataTable = _roleBus.GetRoleById(roleId);
            RoleNameTextBox.Text = dataTable.Rows[0]["RoleName"].ToString();
            StatusCheckBox.Checked = bool.Parse(dataTable.Rows[0]["Status"].ToString());
        }

        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            var role = new Role();
            var roleId = new Guid(Request.QueryString["Id"]);
            role.RoleId = roleId;
            role.RoleName = RoleNameTextBox.Text;
            role.Status = bool.Parse(StatusCheckBox.Checked.ToString());
            _roleBus.UpdateRoleById(role);
            MessageLabel.Visible = true;
            MessageLabel.Text = "Update Successful!";
            RoleNameTextBox.Text = "";
            StatusCheckBox.Checked = false;
        }
    }
}
